<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib uri="http://www.goodfox.com/jsp/tags/power" prefix="p"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<script type="text/javascript">
$(function(){
	$("#role_add_roleScope").change(function(){
		var roleScope=$("#role_add_roleScope").val();
		if(roleScope!='0'){
			$("input[name^='role_add_cbFun']").each(function(){
				if($(this).attr("scope")!=roleScope && $(this).attr("scope")!="0"){
					$(this).attr("checked",false);
					$(this).attr("disabled","disabled");
				}else{
					$(this).attr("disabled",false);
				}
			});
		}else{
			$("input[name^='role_add_cbFun']").each(function(){
				$(this).attr("disabled",false);
			});
		}
	});
	
});
function cleanRoleAddFrom(){
	$("#role_add_roleName").attr("value","");
	$("#role_add_roleDesc").attr("value","");
	$("input[name^='role_add_cbFun']").each(function(){
		$(this).attr("checked",false);
	});
}
function roleAddSubmit(formObj){
	var funIds="";
	var funNames="";
	$("input[name^='role_add_cbFun']").each(function(){
		if($(this).attr("checked")=="checked"){
			funIds+=$(this).attr("value")+";";
			funNames+=$(this).attr("title")+";";
		}
	});
	$("#role_add_funIds").attr("value",funIds);
	$("#role_add_funNames").attr("value",funNames);
	$("#role_add_scopeName").val($("#role_add_roleScope").find("option:selected").text());
	return validateCallback(formObj,navTabAjaxDone);
}
</script>
<div class="pageContent" style="border-left: 1px solid #B8D0D6;border-right: 1px solid #B8D0D6;">
	<div class="panelBar">
		<ul class="toolBar">
			<li><span><spring:message code="search.lnkGoAdd"/>角色</span></li>
			<li class="line">line</li>
		</ul>
	</div>
    <form id="addRoleFrom" action="<c:url value="/role/roleAdd.shtml"/>" method="post" onsubmit="return roleAddSubmit(this);">
	<table class="tableForm" cellpadding="0" cellspacing="1" width="100%" align="center">
		<tbody>
	        <tr>
	            <td>角色名称：</td>
	            <td>
	                <input type="text" class="required" name="role_add_roleName" id="role_add_roleName" maxlength="15" />
	            </td>
	            <td>适用范围：</td>
	            <td>
	                <select class="required" name="role_add_roleScope" id="role_add_roleScope">
	                	<option value="">--请选择--</option>
	           			<c:forEach items="${scopeList}" var="atrScope">
	           				<option value="${atrScope.atrValue}">${atrScope.atrName}</option>
	           			</c:forEach>
	           		</select>
	    			<input type="hidden" name="role_add_scopeName" id="role_add_scopeName"/>
	            </td>
	        </tr>
	        <tr>
	        	<td>系统功能：</td>
	        	<td colspan="3">
		         	<input type="hidden" name="role_add_funIds" id="role_add_funIds"/>
		         	<input type="hidden" name="role_add_funNames" id="role_add_funNames"/>
		         	<table width="100%">
		         		<tbody>
				           <c:forEach items="${funSet}" var="fun">
				           <tr>
				               <td>
				               <input type="checkbox" name="role_add_cbFun" value="${fun.funId}" scope="${fun.funScope}" title="${fun.funName}" class="checkboxCtrl"/>
				               ${fun.funName}
				               </td>
				           </tr>
		                   <c:forEach items="${fun.realSubFunSet}" var="subFun">
		                   <tr>
		                       <td style="padding-left:25px;">
			                       <input type="checkbox" name="role_add_cbFun" value="${subFun.funId}" scope="${subFun.funScope}" title="${subFun.funName}" class="checkboxCtrl"/>
			                       ${subFun.funName}
			                       <c:if test="${subFun.realSubCount>0}">
			                       [
			                       <c:forEach items="${subFun.realSubFunSet}" var="sonFun">
				                       <input type="checkbox" name="role_add_cbFun" value="${sonFun.funId}" scope="${sonFun.funScope}" title="${sonFun.funName}" />
				                       ${sonFun.funName}
			                       </c:forEach>
			                       ]
			                       </c:if>
		                       </td>
		                   </tr>
		                   </c:forEach>
					       </c:forEach>
		         		</tbody>
		         	</table>
	        	</td>
	        </tr>
		</tbody>
	</table>
	<div class="panelBar">
        <div class="buttonActive">
        <c:if test="${p:isPower('/role/roleAdd.shtml',sessionScope.loginAccount)}">
        <div class="buttonContent"><button type="submit"><spring:message code="add.btnAdd"/></button></div>
        </c:if>
        </div>
	</div>
	</form>
</div>